package com.springcloud.learn.web.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;


@Service
public class CalcService {
	
	@Autowired
	RestTemplate restTemplate;
	
	@Value("${service.name}")
	String service;

	@HystrixCommand(fallbackMethod = "addError")
	public Integer add (Integer a , Integer b) {
		return restTemplate.getForEntity("http://"+service+"/add?a="+a+"&b="+b, Integer.class).getBody();
	}
	
	public Integer addError (Integer a , Integer b) {
		return 0;
	}
}
